<?php 

namespace Admin\Controller;
use Think\Controller;
class UserController extends CommonController {

		public function _initialize(){
			parent::_initialize();
			$this->muneclass = 'open';
			$this->muneact = 'active';
		}

		/**
		 * [index 管理员视图]
		 * @return [type] [description]
		 */
		public function index () {
			$this->title = '管理员列表';
			$this->class = 'active';
			$mode = M('admin');
			$count = $mode->count();
			$Page       = new \Think\Page($count,20);
			$this->list = $mode->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
			$this->show = $Page->show2();
			$this->display(':userList');

		}

		public function addview () {
			$this->title = '添加管理员';
			$this->useraddclass = 'active';
			$this->display(':userAdd');
		}

		public function addHalt () {
			if (I('username')) {
				$data['username'] = I('username');
				$data['password'] = I('pwd','','md5');
				$data['addtime'] = time();
				if (I('switch-field-1')) {
					$data['status'] = 1;
				}else{
					$data['status'] = 0;
				}

				if (M('admin')->add($data)) {
					$this->success('添加成功!',U('index'));
				}else{
					$this->error('添加失败,请返回重试!');
				}
			}
		}

		public function userEdit () {
			if (I('id')) {
				
				$data['username'] = I('username');
				if (I('switch-field-1')) {
					$data['status'] = 1;
				}else{
					$data['status'] = 0;
				}
				
				$data['id'] = I('id');
				if (I('pwd')) {
					$data['password'] = I('pwd','','md5');
				}
				if (M('admin')->save($data)) {					
					$this->success('更新成功!',get_laiyuan());
				}else{
					$this->error('更新失败,请返回重试!');
				}
			}
			
		}

		public function userDelete () {
			if (I('id')) {
				if (M('admin')->where(array('id'=>I('id')))->delete()) {
					$data['status'] = 1;
					$data['info'] = '删除成功!';
				}else{
					$data['status'] = 0;
					$data['info'] = '删除失败!';
				}
			}else{
				$data['status'] = 0;
				$data['info'] = '非法操作!';
			}
			echo json_encode($data);
		}
}






 ?>